Covid 19 - the game

Advanced game related topics
User avatar
SPH
Enthusiast
Enthusiast
Posts: 269
Joined: Tue Jan 04, 2011 6:21 pm

Covid 19 - the game

Post by SPH »

Hello everybody !

In this period of confinement, I had an inspiration. I coded a Covid-19 contamination game :

MAJ (06 may 2020) : http://xmas.free.fr/Covid-19_The_game.zip


Enjoy :P
Last edited by SPH on Wed May 06, 2020 1:52 pm, edited 2 times in total.
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 5.73LTS - 32 bits
User avatar
SPH
Enthusiast
Enthusiast
Posts: 269
Joined: Tue Jan 04, 2011 6:21 pm

Re: Covid 19 - the game

Post by SPH »

Image

Image
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 5.73LTS - 32 bits
User avatar
SPH
Enthusiast
Enthusiast
Posts: 269
Joined: Tue Jan 04, 2011 6:21 pm

Re: Covid 19 - the game

Post by SPH »

MAJ in post 1

"covid.pb" is in the zip.

:wink: :!:
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 5.73LTS - 32 bits
User avatar
GG
Enthusiast
Enthusiast
Posts: 258
Joined: Tue Jul 26, 2005 12:02 pm
Location: Lieusaint (77), France

Re: Covid 19 - the game

Post by GG »

Not important : May instead of March in first post ?
Purebasic 6.04 64 bits - Windows 11 Pro 64 bits 23H2
User avatar
SPH
Enthusiast
Enthusiast
Posts: 269
Joined: Tue Jan 04, 2011 6:21 pm

Re: Covid 19 - the game

Post by SPH »

GG wrote:Not important : May instead of March in first post ?
OOPS... yes :oops:
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 5.73LTS - 32 bits
User avatar
SPH
Enthusiast
Enthusiast
Posts: 269
Joined: Tue Jan 04, 2011 6:21 pm

Re: Covid 19 - the game

Post by SPH »

Code: Select all

; PB 5.70LTS
;
; Code et graphismes : SPH
; Codé le 20 avril 2020
; Corrigé le 6 mai 2020
; (c)2020
; 
;

If InitSprite() = 0
  MessageRequester("Erreur", "Unable to open the screen & sprites !", 0)
  End
EndIf
If InitMouse() = 0
  MessageRequester("Erreur", "Unable to activate mouse !", 0)
  End
EndIf
If InitKeyboard() = 0
  MessageRequester("Erreur", "Unable to activate keyboard !", 0)
  End
EndIf

LoadFont(1000, "Arial", 20)
LoadFont(1001, "Arial", 30)
LoadFont(1002, "Arial", 15)

If OpenWindow(0, 0, 0, 780, 560, "Covid-19", #PB_Window_ScreenCentered)
  
  
  If OpenWindowedScreen(WindowID(0), 0, 0, 780, 560)
    
    
    contamines=0
    guerisons=0
    deces=0
    stop=0
    ok=0
    ok2=0
    ici=0
    piece=0
    difficulte=250
    
    Dim item(3)
    For i=0 To 3
      item(i)=44
    Next
    
    
    
    LoadSprite(0,"france5.bmp") 
    
    Dim m(548,562)
    
    Dim op0(548,562)
    Dim op1(548,562)
    Dim op2(548,562)
    Dim op3(548,562)
    
    Dim p(548,562)
    If StartDrawing(SpriteOutput(0))
      For u=0 To 561
        For i=0 To 547
          x=Point(i,u)
          p(i,u)=x
          If x=RGB(0,255,0)
            combien+1
          EndIf
          
        Next
      Next
      StopDrawing()
    EndIf
    
    FreeSprite(0)
    
    
    
  Else
    MessageRequester("Erreur", "Unable to open screen in window !", 0)
    End
  EndIf
EndIf

; ReleaseMouse(1)

LoadSprite(100,"pointeur.bmp") 

;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
LoadSprite(1,"b0.bmp") 
LoadSprite(2,"titre.bmp") 

FlipBuffers() 
Delay(100)

Repeat
  While WindowEvent():Wend  ;<<-----------------------------
  DisplaySprite(1, 548,0)
  DisplaySprite(2,0,0)
  
  
  ExamineMouse()            ; Etat de la souris
  xm = MouseX()             ; Position en x de la souris                     
  ym = MouseY()             ; Position en y de la souris
  
  DisplayTransparentSprite(100,xm,ym)
  
  ExamineKeyboard()
  
  If KeyboardPushed(#PB_Key_Escape)
    End
  EndIf
  
  
  FlipBuffers() 
  Delay(1)  
Until MouseButton(1)=1
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;

For i=0 To 16
  LoadSprite(i+9,"c"+Str(i)+".bmp")
Next



;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;



Repeat
  ; Il est très important de traiter tous les évènements restants dans la file d'attente à chaque tour
  Repeat
    Event = WindowEvent()
    Select Event 
      Case #PB_Event_CloseWindow
        End 
    EndSelect
  Until Event = 0
  
  While WindowEvent():Wend  ;<<-----------------------------
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ExamineMouse() ; Etat de la souris
  xm = MouseX()  ; Position en x de la souris                     
  ym = MouseY()  ; Position en y de la souris
  
  
  For z=1 To difficulte
    i=Random(545)+1
    u=Random(557)+1
    
    
    ;;;;;;; la guerison (jaune) apres la pandemie
    If stop>=48
      If p(i,u)=RGB(0,255,0) Or p(i,u)=RGB(255,0,0)
        nb2=0
        For ii=-1 To 1
          For uu=-1 To 1
            If p(i+ii,u+uu)=RGB(255,255,0)
              nb2+1
            EndIf
          Next
        Next
        If nb2>2
          p(i,u)=RGB(255,255,0) : guerisons+1
        EndIf
      EndIf
    EndIf
    
    
    
    If p(i,u)=RGB(0,255,0)
      nb=0
      For ii=-1 To 1
        For uu=-1 To 1
          If p(i+ii,u+uu)=RGB(255,0,0)
            nb+1
          EndIf
        Next
      Next
      
      ;       If nb>0 And Random(200)=0
      ;         p(i,u)=RGB(255,255,0) : guerisons+1
      ;       EndIf
      
      
      If nb>0 And Random(op1(i,u))=0 And Random(op2(i,u))=0 And Random(op3(i,u))=0
        p(i,u)=RGB(255,0,0) : contamines+1
        m(i,u)+1
        op1(i,u)-1
        If op1(i,u)<0
          op1(i,u)=0
        EndIf
        op2(i,u)-1
        If op2(i,u)<0
          op2(i,u)=0
        EndIf
        op3(i,u)-1
        If op3(i,u)<0
          op3(i,u)=0
        EndIf
      EndIf
      
    Else
      
      If p(i,u)=RGB(255,0,0)
        m(i,u)+1
        If m(i,u)>10+op0(i,u) ; bandages
          p(i,u)=RGB(50,50,255) : deces+1
          op0(i,u)=0
        EndIf
        If Random(100)=0 And op0(i,u)>0
          op0(i,u)-1
        EndIf
      EndIf
      
    EndIf
    
    
    ;;;;;;;; attenuation des bandages, vaccins, pilulles et masques
    
    If Random(40)=0 And op0(i,u)>0
      op0(i,u)-1
    EndIf
    If Random(50)=0 And op1(i,u)>0
      op1(i,u)-1
    EndIf
    If Random(40)=0 And op2(i,u)>0
      op2(i,u)-1
    EndIf
    If Random(10)=0 And op3(i,u)>0
      op3(i,u)-1
    EndIf
    
  Next z
  
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;   qqq+1
  ;   If qqq>10
  ;     Goto la
  ;   EndIf
  
  
  If Random(100)=0 And cursor=0 And stop<51
    i=Random(546)
    u=Random(558)
    If p(i,u)=RGB(0,255,0)
      stop+1
      cursor=1
      cursorx=i
      cursory=u
      p(i,u)=RGB(255,0,0)
      m(i,u)+1
      p(i+1,u)=RGB(255,0,0) 
      m(i+1,u)+1
      p(i,u+1)=RGB(255,0,0) 
      m(i,u+1)+1
      p(i+1,u+1)=RGB(255,0,0) 
      m(i+1,u+1)+1
      contamines+1
    EndIf
  EndIf
  
  
  
  If stop>=51
    timer+1
    If timer>150
      Debug "..."
      Debug score
      If score=contamines
        la:
        Debug "fin" ;- fin
        StartDrawing(ScreenOutput())
        Box(0,0,548,562,RGB(0,15,26))
        
        a$="Congratulation"
        DrawingFont(FontID(1001))
        BackColor(RGB(0,15,26))
        DrawText(190,60,a$, RGB(255,255,255))
        
        a$="You stopped the epidemic but at what cost..."
        DrawingFont(FontID(1002))
        BackColor(RGB(0,15,26))
        DrawText(50,160,a$, RGB(200,255,100))
        
        a$="The death count is "+Str(deces)+" ("+Str(deces*100/combien)+"%)"
        
        
        DrawingFont(FontID(1002))
        BackColor(RGB(0,15,26))
        DrawText(50,200,a$, RGB(200,255,100))
        
        If guerisons>deces
          a$="The number of healings is greater" 
        Else
          a$="The number of healings is less"
        EndIf
        DrawingFont(FontID(1002))
        BackColor(RGB(0,15,26))
        DrawText(50,240,a$, RGB(200,255,100))
        a$="than death"
        DrawingFont(FontID(1002))
        BackColor(RGB(0,15,26))
        DrawText(50,265,a$, RGB(200,255,100))
        
        
        a$="You're a butcher ... Sorry !"
        If deces<2600
          a$="You are not a good doctor"
        EndIf
        If deces<2200
          a$="You are a good doctor"
        EndIf
        If deces<1800
          a$="You are a very good doctor"
        EndIf
        If deces<1400
          a$="You are an excellent doctor !"
        EndIf
        
        DrawingFont(FontID(1002))
        BackColor(RGB(0,15,26))
        DrawText(50,310,a$, RGB(200,255,100))
        
        a$="Remember: if you like scrabble, go on my site :"
        DrawingFont(FontID(1002))
        BackColor(RGB(0,15,26))
        DrawText(50,480,a$, RGB(40,40,40))
        a$="http://hexascrabble.com"
        DrawingFont(FontID(1002))
        BackColor(RGB(0,15,26))
        DrawText(50,505,a$, RGB(40,40,40))
        
        
        StopDrawing()
        FlipBuffers() 
        
        Repeat
          While WindowEvent():Wend  ;-<<-----------------------------
          Delay(1)
          ExamineKeyboard()
          
        Until KeyboardPushed(#PB_Key_Escape)
        
        End
      EndIf
      timer=0
      score=contamines
    EndIf
    
  EndIf
  
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
  
  DisplaySprite(1, 548,0)
  
  StartDrawing(ScreenOutput())
  For u=0 To 559
    For i=0 To 547
      Plot(i,u,p(i,u))
    Next
  Next
  
  
  a$=Str(contamines)
  DrawingFont(FontID(1000))
  BackColor(RGB(34,34,34))
  DrawText(548+117-TextWidth(a$)/2,50,a$, RGB(255,0,0))
  
  a$=Str(guerisons)
  DrawingFont(FontID(1000))
  BackColor(RGB(34,34,34))
  DrawText(548+117-TextWidth(a$)/2,50+94,a$, RGB(255,255,0))
  
  a$=Str(deces)
  DrawingFont(FontID(1000))
  BackColor(RGB(34,34,34))
  DrawText(548+117-TextWidth(a$)/2,50+94*2,a$, RGB(50,50,255))
  
  ;   a$=Str(xm)
  ;   DrawingFont(FontID(1000))
  ;   BackColor(RGB(34,34,34))
  ;   DrawText(40,50,a$, RGB(50,50,255))
  ;   a$=Str(ici)
  ;   DrawingFont(FontID(1000))
  ;   BackColor(RGB(34,34,34))
  ;   DrawText(120,50,a$, RGB(50,50,255))
  
  
  
  
  If ok=2
    If ici>=6 And ici<=9
      item(9-ici)+4
      ok=0
    EndIf
  EndIf
  
  
  
  If Random(20)=0
    u=Random(3)
    item(u)+1
    If item(u)>44
      item(u)=44
    EndIf
  EndIf
  
  
  For i=0 To 3
    If item(i)>44
      item(i)=44
    EndIf
    If item(i)>=11
      Box(556+57*i,370,item(i),3,RGB(0,255,0))
    Else
      Box(556+57*i,370,item(i),3,RGB(255,0,0))
    EndIf
  Next
  
  Box(548+16,94*3+35,stop*4,2,RGB(0,255,0))
  
  
  ;;;;
  
  
  
  
  
  
  If piece=0 And MouseButton(1)=1    
    If xm>550; And xm<730
      If ym>380;400 And ym<530
        
        Angle +20
        If angle>340
          angle=0
        EndIf
        
        Xx = 664 + 42 * Cos(Angle * #PI / 180)
        
        Yy = 464 + 42 * Sin(Angle * #PI / 180)
        
        Circle(Xx, Yy, 2, RGB(0,255,0))
        
        ici=21-(angle/20)
        If ici=4
          ici=22
        EndIf
        If ici=5
          ici=23
        EndIf
        
        ok=1
      EndIf
    EndIf
  EndIf
  
  
  If ok=1 And MouseButton(1)=0
    
    If ici>=10 And ici<=23
      piece=1
      ok=0
    Else
      ok=2
    EndIf
    
  EndIf
  
  
  
  
  
  If piece=0 And MouseButton(1)=0
    For i=0 To 3
      If xm>554+i*57 And xm<603+i*57
        If ym>327 And ym<376
          DrawingMode(#PB_2DDrawing_Outlined)
          Box(554+i*57,327,49,49,RGB(200,200,200))
        EndIf
      EndIf
    Next
  EndIf
  
  
  
  If piece=0 And MouseButton(1)=1    
    For i=0 To 3
      If xm>554+i*57 And xm<603+i*57
        If ym>327 And ym<376
          If item(i)>=11
            piece=10+i
          Else
            piece=0
          EndIf
        EndIf
      EndIf
    Next
  EndIf
  
  
  If piece=1 ;And MouseButton(1)=0   
    Circle(Xx, Yy, 2, RGB(0,255,0))
  EndIf
  
  
  If piece>=10 And item(piece-10)>=11
    DrawingMode(#PB_2DDrawing_Outlined)
    i=piece-10
    Box(554+i*57,327,49,49,RGB(255,0,255))
  EndIf
  
  
  
  If piece>=10 And MouseButton(1)=0    
    ok2=1
  EndIf
  
  
  If piece>=10 And ok2=1 And MouseButton(1)=1
    For i=-23 To 23
      For u=-23 To 23
        If xm+i>=0 And xm+i<=548 And ym+u>=0 And ym+u<=562
          
          If p(xm+i,ym+u)=RGB(0,255,0) Or p(xm+i,ym+u)=RGB(255,0,0)
            
            
            ;- les bandages sur rouge resistent a la mort
            ;- le vaccin guerris (attention a l'overdose)
            ;- les pillules soignent le rouge (attention a l'overdose)
            ;- le masque ralenti la propagation  
            
            
            If piece-10=3 ;-masque
              op3(xm+i,ym+u)+Random(5)+5
            EndIf
            
            If piece-10=0 And p(xm+i,ym+u)=RGB(255,0,0) ;-bandages
              op0(xm+i,ym+u)+Random(10)+5
            EndIf
            
            If piece-10=2 And p(xm+i,ym+u)=RGB(255,0,0) ;-pilulles
              op2(xm+i,ym+u)+3
              If Random(10)=0
                p(xm+i,ym+u)=RGB(255,255,0)
                guerisons+1
              EndIf
              
              ;Debug op2(xm+i,ym+u)
              If op2(xm+i,ym+u)>11
                p(xm+i,ym+u)=RGB(50,50,255)
                op2(xm+i,ym+u)=0
                deces+1
              EndIf
              
            EndIf
            
            
            If piece-10=1 ;-seringue
              op1(xm+i,ym+u)+4
              If op1(xm+i,ym+u)>15
                If Random(2)=0
                  p(xm+i,ym+u)=RGB(50,50,255)
                  op1(xm+i,ym+u)=0
                  deces+1
                EndIf
              Else
                If Random(10)=0 ;And p(xm+i,ym+u)=RGB(255,0,0)
                  p(xm+i,ym+u)=RGB(255,255,0)
                  guerisons+1
                EndIf
              EndIf
            EndIf
            
            
            
            
          EndIf
          
          
          
        EndIf
      Next
    Next
    item(piece-10)-11
    If item(piece-10)<0
      item(piece-10)=0
    EndIf
    piece=0
    ok2=0
  EndIf
  
  ;;;;  
  
  
  StopDrawing()
  
  
  
  
  If piece=1 And MouseButton(1)=1    
    If xm<549
      If StartDrawing(SpriteOutput(ici))
        For i=0 To 39
          For u=0 To 39
            If xm+i<549 And ym+u<560
              p=Point(i,u)
              If p<>0
                piece=0
                
                If p(xm+i,ym+u)=RGB(0,255,0)
                  p(xm+i,ym+u)=RGB(255,255,255)
                EndIf
                
                If p(xm+i,ym+u)=RGB(255,0,0)
                  p(xm+i,ym+u)=RGB(255,255,255)
                EndIf
                
              EndIf
            EndIf
          Next
        Next
        StopDrawing()
      EndIf
    EndIf
  EndIf
  
  
  ;;;;;;;;;;;;;;
  If cursor<>0
    cursor+1
    If cursor>50
      cursor=0
    EndIf
    ;Debug cursor%8
    If cursor%8>3
      DisplayTransparentSprite(24,cursorx-23,cursory-23)
    Else
      DisplayTransparentSprite(25,cursorx-23,cursory-23)
    EndIf
  EndIf
  ;;;;;;;;;;;;;;
  
  
  If piece=0
    DisplayTransparentSprite(100,xm,ym)
  ElseIf piece=1
    DisplayTransparentSprite(ici,xm,ym)
  ElseIf piece>=10
    DisplayTransparentSprite(9,xm-23,ym-23)
  EndIf
  
  
  FlipBuffers() 
  
  Delay(1)
  
  ExamineKeyboard()
  
Until KeyboardPushed(#PB_Key_Escape)

End

http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 5.73LTS - 32 bits
Post Reply